package pers.zh.parking.mvp.model;

import android.app.Application;

import com.google.gson.Gson;

import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;

import com.jess.arms.di.scope.ActivityScope;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observable;
import pers.zh.parking.common.ApiService;
import pers.zh.parking.common.BaseResponse;
import pers.zh.parking.common.Const;
import pers.zh.parking.data.entity.Car;
import pers.zh.parking.data.entity.ParkRecord;
import pers.zh.parking.mvp.contract.ReservationContract;

@ActivityScope
public class ReservationModel extends BaseModel implements ReservationContract.Model {

    @Inject
    Gson mGson;
    @Inject
    Application mApplication;

    @Inject
    public ReservationModel(IRepositoryManager repositoryManager) {
        super(repositoryManager);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<BaseResponse<List<ParkRecord>>> getReservations(int userId) {
        return mRepositoryManager.obtainRetrofitService(ApiService.class).getReservations(userId,
                Const.ParkingStatus.RESERVE);
    }

    @Override
    public Observable<BaseResponse> cancel(long recordId) {
        return mRepositoryManager.obtainRetrofitService(ApiService.class).cancelReservation(recordId);
    }

    @Override
    public Observable<BaseResponse> park(long recordId, String carNo) {
        return mRepositoryManager.obtainRetrofitService(ApiService.class).park(recordId, carNo);
    }

    @Override
    public Observable<BaseResponse> pay(long recordId) {
        return mRepositoryManager.obtainRetrofitService(ApiService.class).pay(recordId);
    }

    @Override
    public Observable<BaseResponse<List<Car>>> getCars(String userId) {
        return mRepositoryManager.obtainRetrofitService(ApiService.class).getCars(userId);
    }
}